package ericXie.com.component 
{
	import ericXie.com.model.MainModel;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	/**
	 * ...转盘类
	 * @author EricXie
	 */
	public class RouletteMovieClip extends MovieClip 
	{
		//转盘
		public var _roulette:MovieClip;
		//自动旋转
		private var _autoRotation:Boolean;
		//旋转速度
		private var _rotateSpeed:Number=1;
		private var _model:MainModel=MainModel.getInstance();
		
		public function RouletteMovieClip() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, addStageHandler);
		}
		
		private function addStageHandler(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, addStageHandler);
			_roulette = _model.extractionElements("Roulette") as MovieClip;
			this.addChild(_roulette);
			
		}
		//是否自动旋转
		public function get autoRotation():Boolean 
		{
			return _autoRotation;
		}
		
		public function set autoRotation(value:Boolean):void 
		{
			_autoRotation = value;
			if (_roulette!=null) {
				if (_autoRotation) {
					this.addEventListener(Event.ENTER_FRAME, enterFrameAutoRotation,false,0,true);
				}else {
					this.removeEventListener(Event.ENTER_FRAME, enterFrameAutoRotation);
				}
			}
			
		}
		//旋转速度
		public function get rotateSpeed():Number 
		{
			return _rotateSpeed;
		}
		
		public function set rotateSpeed(value:Number):void 
		{
			_rotateSpeed = value;
		}
		//设置自动旋转
		private function enterFrameAutoRotation(e:Event):void 
		{
			_roulette.rotation += rotateSpeed;
		}
		
	}

}